package demo1;

import java.util.*;

/**
 * @Author liangzai
 * @Description:
 */
public class Test {
    public int superEggDrop(int k, int n) {
        int x = k-1;
        int count = 0;
        while (n > 0) {
            n -= k;
            k += k;
            count++;
        }
        return count;
    }

    public List<List<Integer>> threeSum(int[] nums) {
        Arrays.sort(nums);
        List<List<Integer>> list = new LinkedList<>();
        int l = 0;
        while (l <= nums.length - 3) {
            if(l!=0 && nums[l] == nums[l-1]){
                l++;
                continue;
            }
            int key = -nums[l];
            int ll = l-1;
            int rr = nums.length-1;
            while (ll < rr) {
                if(ll!=l-1 && nums[ll] == nums[ll-1]){
                    ll++;
                    continue;
                }
                if(rr!=nums.length-1 && nums[rr] == nums[rr+1]){
                    rr--;
                    continue;
                }
                List<Integer> list1 = new LinkedList<>();
                if((nums[ll] + nums[rr]) == key){
                    list1.add(nums[l]);
                    list1.add(nums[ll]);
                    list1.add(nums[rr]);
                    ll++;
                    rr--;
                    continue;
                }else if(nums[ll] + nums[rr] > key){
                    rr--;
                }else {
                    ll++;
                }
                list.add(list1);
            }
            l++;
        }
        return list;
    }

    public static void main1(String[] args) {
        String[] array = {"202499001234","123456789111","202499008523"};
        for (int i = 0; i < array.length; i++) {
            if(array[i].length() == 12){
                String str = "2024";
                int j = 0;
                for (; j < 4; j++) {
                    if(array[i].charAt(j) != str.charAt(j)){
                        System.out.println("不正确");
                        break;
                    }
                }
                if(4==j){
                    System.out.println("正确");
                }
            }else {
                System.out.println("不正确");
            }
        }
    }



    public boolean isValid(String s) {
        Deque<Character> stack = new LinkedList<>();
        HashMap<Character,Character> map = new HashMap<>();
        map.put('(',')');
        map.put('{','}');
        map.put('[',']');

        for (int i = 0; i < s.length(); i++) {
            if (stack.isEmpty()) {
                stack.push(s.charAt(i));
                continue;
            }
            char tmp = stack.peek();
            if(map.get(tmp).equals(s.charAt(i))){
                stack.pop();
            }else{
                stack.push(s.charAt(i));
            }
        }
        return stack.isEmpty();
    }
}
